package com.jiuyun.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
  自定义servlet 父类
  
  
 */
public class BaseServlet extends HttpServlet {
	
	protected void service(HttpServletRequest request, HttpServletResponse response)
	{
		//   项目名/user/*   *=find 或者insert 会调用相对应方法
		String url=request.getRequestURI();
		int gang=url.lastIndexOf("/");
		String work=url.substring(gang+1);
//		System.out.println("你在干嘛啊"+work);
			
		// 方法
		Method m=null;
		try {
			m=this.getClass().getDeclaredMethod(work, HttpServletRequest.class,HttpServletResponse.class);
			//System.out.println(m.getName());
			//调用
			m.invoke(this, request,response);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("没有此方法");
		} 
	}
};
